<?php
include(dirname(__FILE__) . "/get_result.php");

//$imagepath=("uploads/" . $_FILES["datei"]["name"]);
  //$photo = "/opt/lampp/htdocs/badge5/uploads/erik_by_scale.jpg"
  $imagepath = $photo;
  $maxwidth = 207;
  $maxheight = 166;

//set mime type content

header('Content-Type: image/jpeg');


//create original image

$image = imagecreatefromjpeg($imagepath);

//get image dimension

$dim=getimagesize($imagepath);
 $width = $dim[1];
 $height = $dim[0];

//Set thumb dimension

//$thumbw = 207;
//$thumbh = 166;


//determine which side is the longest to use in calculating length of the shorter side, since the longest will be the max size for whichever side is longest.    
if ($height > $width) 
{   
$ratio = $maxheight / $height;  
$newheight = $maxheight;
$newwidth = $width * $ratio; 
}
else 
{
$ratio = $maxwidth / $width;   
$newwidth = $maxwidth;  
$newheight = $height * $ratio;   
}

$thumbw = $newheight;
$thumbh = $newwidth;
//create empty image

$thumb_image=imagecreatetruecolor($thumbw, $thumbh);

//Resize original image and copy it to thumb image

imagecopyresampled($thumb_image, $image, 0, 0, 0, 0,
					$thumbw, $thumbh, $dim[0], $dim[1]);


//display thumb image
imagejpeg($thumb_image);
imagedestroy($thumb_image);
?>
